<html>
<head><meta charset="utf-8"><title>magic -&gt; stdlib array Copy &amp; Clone · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/magic.20-.3E.20stdlib.20array.20Copy.20.26.20Clone.html">magic -&gt; stdlib array Copy &amp; Clone</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241177662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/magic%20-%3E%20stdlib%20array%20Copy%20%26%20Clone/near/241177662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/magic.20-.3E.20stdlib.20array.20Copy.20.26.20Clone.html#241177662">(Jun 02 2021 at 16:57)</a>:</h4>
<p>somewhere in the compiler is some magic that allows all tuples and function pointers to implement Copy/Clone regardless of arity. Presumably this is the same code that has always allowed arrays of all sizes to implement Copy/Clone, even before const generics existed. now that const generics exist I was curious about removing this magic from the compiler and into ordinary impls in std. Does anyone know where in the compiler this code lives?</p>



<a name="241177878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/magic%20-%3E%20stdlib%20array%20Copy%20%26%20Clone/near/241177878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/magic.20-.3E.20stdlib.20array.20Copy.20.26.20Clone.html#241177878">(Jun 02 2021 at 16:59)</a>:</h4>
<p>also, whether or not this would be a good idea; I'd hope that it's perf-neutral, but I really have no clue</p>



<a name="241179233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/magic%20-%3E%20stdlib%20array%20Copy%20%26%20Clone/near/241179233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/magic.20-.3E.20stdlib.20array.20Copy.20.26.20Clone.html#241179233">(Jun 02 2021 at 17:09)</a>:</h4>
<p>This branch makes the trait system think that the traits are implemented: <a href="https://github.com/rust-lang/rust/blob/01e9d09d3bbb35a1fbb0a2a353cfcf90a4feb050/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1632-L1635">https://github.com/rust-lang/rust/blob/01e9d09d3bbb35a1fbb0a2a353cfcf90a4feb050/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1632-L1635</a><br>
Removing array from this match would then make the compiler use the implementation written in the impl block: <a href="https://github.com/rust-lang/rust/blob/30187c81f65aa29a53ad7c24fe3b4c7bff947094/compiler/rustc_ty_utils/src/instance.rs#L256">https://github.com/rust-lang/rust/blob/30187c81f65aa29a53ad7c24fe3b4c7bff947094/compiler/rustc_ty_utils/src/instance.rs#L256</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>